var AddDailyBalancePay = {};
AddDailyBalancePay.contextpath = "";
AddDailyBalancePay.initPage = function(contextpath) {
	AddDailyBalancePay.contextpath = contextpath;

	layui.use(['form', 'layedit', 'laydate'], function(){
		  var form = layui.form
		  ,layer = layui.layer
		  ,laydate = layui.laydate;
		  
		  //日期
		  laydate.render({
		    elem: '#date'
		  });
		  //监听提交
		  form.on('submit(submit)', function(data){
//		    layer.alert(JSON.stringify(data.field), {
//		      title: '最终的提交信息'
//		    })
			  AddDailyBalancePay.ajaxSaveDailyBalancePay(data);
		    return false;
		  });
		});
}


AddDailyBalancePay.ajaxSaveDailyBalancePay = function(data1) {
	$.ajax({
		type : "POST",
		url : "/web2019/finance/ajaxSaveDailyBalancePay.action",
		dataType : "json",
		data : data1.field,
		beforeSend:function(){
			layer.load(1);
		},
		complete:function(){
			layer.close(layer.index-1);
		},
		success : function(data) {
			if (data.code == "0000") {
				layer.alert(data.message, { icon: 1, closeBtn: 0 }, function (index) { 
					layer.close(index);
					var client =AddDailyBalancePay.getClient();
					if(client=="pc"){
						window.location.href="/web2019/finance/addDailyBalancePay.action";
					}else{
						window.location.href="/"+AddDailyBalancePay.contextpath+"/mobile/index.action";
					}
				});
			} else {
				layer.alert(data.message);
			}
		},
		error : function(data) {

		}
	});
}

AddDailyBalancePay.getClient =function(){
	if(/Android|webOS|iPhone|iPod|BlackBerry|iPad|SymbianOS/i.test(navigator.userAgent)) {
	    console.log("is mobile ")
	    return "mobile";
	 } else {
	    console.log("is pc ")
	    return "pc";
	}}
